<!-- 权限设置 -->
<template>
    <div >
        <div class='table-page-search-wrapper'>
            <a-form layout='inline'>
               <a-row :gutter='48'>
                    <a-col :md='8' :sm='24'>
                        <a-form-item>
                            <a-input-search v-model="query" placeholder="输入操作员姓名/手机号" allow-clear @search="getData"></a-input-search>
                        </a-form-item>
                    </a-col>
                    <a-col :md='8' :sm='24'>
                    </a-col>
                    <a-col :md='8' :sm='24'>
                        <a-form-item >
                            <a-button type='' @click="add">添加操作员</a-button>
                        </a-form-item>
                    </a-col>
                </a-row>
            </a-form>
        </div>  

        <a-table rowKey="id" :loading="isload" :columns="columns" :data-source="dataList" @change="handleTableChange"  size="small" :pagination="{ total: total ,showSizeChanger: true,pageSize: size,}" >
            <div slot="state" slot-scope="state">
                <a-badge :status="state | contractStatusTypeFilter" :text="state | contractStatusFilter" />
            </div>
            <div slot="operation" slot-scope="text,record">
                <div class="editable-row-operations">
                    <a-button type="link" @click="detail(record)">详情</a-button>
                    <a-button v-if="record.state == 0" type="link" @click="updateState(record,1)">启用</a-button>
                    <a-button v-else type="link" @click="updateState(record,0)">停用</a-button>
                </div>
            </div>
        </a-table>
    </div>
</template>

<script>
import { userStaffList , updateUserStaffState } from '@/api/services/power';
import { columns } from './table';
import { USER_TYPE } from '@/store/mutation-types';
export default {
    data () {
        return {
            query: '',
            page: 1,
            size: 10,
            total: 0,
            isload: false,
            dataList: [],
            columns,
        };
    },
    created(){
        this.getData();
    },
    methods: {
        // 获取已配置权限信息
        getData(){
            let _this = this;
            _this.isload = true;
            const params = {
                'query': _this.query,
                'pageSize': _this.size,
                'pageIndex': _this.page,
            }
            userStaffList(params)
            .then(res => {
                _this.isload = false;
                if(res.success){
                    _this.dataList = res.data;
                    _this.total = res.totalCount;
                }else{
                    _this.$notification['error']({
                        message: '温馨提示',
                        description: res.errMessage,
                        duration: 8
                    })
                }
            })
        },
        // 分页
        handleTableChange(pagination, filters, sorter) {
            console.log(pagination);
            this.page = pagination.current;
            this.size = pagination.pageSize;
            this.getData()
        },
        // 添加
        add(){
            var userType = sessionStorage.getItem(USER_TYPE)
            var path = userType == '2' ? '/servicesPower/updatePower' : '/companysPower/updatePower';
            this.$router.push({ path: path})
        },
        // 详情
        detail(item){
            var userType = sessionStorage.getItem(USER_TYPE)
            var path = userType == '2' ? '/servicesPower/updatePower' : '/companysPower/updatePower';
            this.$router.push({ path: path, query: {'id': item.id}})
        },
        // 状态切换
        updateState(item,state){
            let _this = this
            _this.$confirm({
                title: '温馨提示',
                content: state == 1 ? '是否确认开启当前员工' : '是否确认关闭当前员工',
                okText: state == 1 ? '确认开启' : '确认关闭',
                onOk() {
                    const params = {
                        'staffId': item.id,
                        'state': state,
                    }
                    updateUserStaffState(params)
                    .then(res=>{
                        if(res.success){
                            _this.$notification['success']({
                                message: '温馨提示',
                                description: state == 1 ? '开启成功' : '关闭成功',
                                duration: 8
                            })
                            _this.getData()
                        }else{
                            _this.$notification['error']({
                                message: '温馨提示',
                                description: res.errMessage,
                                duration: 8
                            })
                        }
                    })
                },
                onCancel() {},
            });
        },
    }
}

</script>
<style scoped>

</style>